<?php

namespace Params;

/**
 * Class WebParams
 *
 * @package Params
 * @author  Jon
 * @link    https://gitee.com/joncc/params
 */
class WebParams extends Params
{
    /**
     * @param *password #密码
     * @return mixed
     * @throws \Exception
     */
    public function password($password)
    {
        $pattern = '/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,18}$/'; //数字和字母6位以上字符
        preg_match_all($pattern, $password, $result);
        if (empty($result[0])) {
            throw new \Exception('必须包含数字和字母6位以上字符', 10000);
        }

        return $password;
    }

    /**
     * @param *email #Email
     * @return mixed
     * @throws \Exception
     */
    public function email($email)
    {
        $pattern = '/^\S{1,}@\S{1,}\.\S{1,}$/'; //x@x.x
        preg_match_all($pattern, $email, $result);
        if (empty($result[0])) {
            throw new \Exception('email有误', 10001);
        }

        return $email;
    }
}